{{include_file name='public/header' title='项目成员'}}
{{$project_id = $project.id}}
{{$is_creater = \app\user::is_creater($project_id)}}
{{$has_delete_rule = \app\member::has_rule($project_id, 'project', 'delete')}}
</head>

<body>

<div id="wrapper">

    <!-- Navigation -->
    {{include_file name='public/nav' sidebar='project_sidebar'}}
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <div class="page-header">
                    <h1>项目成员 </h1>
                    <div class="opt-btn">
                        {{if \app\member::has_rule({{$project.id}}, 'member', 'add')}}
                        <a href="javascript:void(0);" class="btn hidden-xs btn-sm btn-success js_addMemberBtn" data-id="{{$project.id}}-0" data-title='添加成员'><i class="fa fa-fw fa-plus"></i>添加</a>

                        {{/if}}
                    </div>
                </div>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">

            <div class="col-lg-12">

                <div class="panel panel-default">

                    {{include_file name='project/tab'}}

                    <div class="panel-body">
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>成员昵称/邮箱</th>
                                    <th>项目权限</th>
                                    <th>模块权限</th>
                                    <th>接口权限</th>
                                    <th>会员权限</th>
                                    <th>加入时间</th>
                                    {{if $is_creater || $has_delete_rule}}
                                    <th>操作面板</th>
                                    {{/if}}
                                </tr>
                                </thead>
                                <tbody>
                                {{foreach $members as $member}}

                                {{$user_id = $member.user_id}}

                                <tr>
                                    <td>{{\app\user::get_name_email($user_id)}}</td>
                                    <td>{{\app\member::get_rules_title($member.project_rule)}}</td>
                                    <td>{{\app\member::get_rules_title($member.module_rule)}}</td>
                                    <td>{{\app\member::get_rules_title($member.api_rule)}}</td>
                                    <td>{{\app\member::get_rules_title($member.member_rule)}}</td>
                                    <td>{{$member.add_time}}</td>
                                    {{if $is_creater || $has_delete_rule}}
                                    <td>

                                        {{if \app\user::is_creater($project_id)}}
                                        <a type="button" class="btn btn-success btn-xs js_addMemberBtn" data-title="编辑权限" data-id="{{$project.id}}-{{$member.id}}"><i class="fa fa-fw fa-key"></i>权限</a>
                                        {{/if}}

                                        {{if \app\member::has_rule({{$project_id}}, 'project', 'delete')}}
                                        <a type="button" class="btn btn-danger btn-xs js_quitProjectBtn" data-id="{{$member.id}}"><i class="fa fa-fw fa-sign-out"></i>移除</a>
                                        {{/if}}

                                    </td>
                                    {{/if}}


                                </tr>
                                {{/foreach}}

                                </tbody>
                            </table>
                            {{include_file name='public/page'}}
                        </div>
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
        </div>

    </div>
    <!-- /#page-wrapper -->




</div>
<!-- /#wrapper -->
<div class="modal fade" id="js_addMemberModal" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">添加成员</h4>
            </div>
            <div class="modal-body">

                <iframe id="js_addMemberIframe" style="min-height: 330px;" src="{{url('member/add')}}"></iframe>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary js_submit">提交</button>
            </div>

        </div>

    </div><!-- /.modal-dialog -->
</div>
<hr>
<p class="text-center">{{get_config('copyright')}}</p>
<script>
    $(function(){

        // 添加/编辑成员
        $(".js_addMemberBtn").iframeModal({
            modalItem: '#js_addMemberModal', //modal元素
            iframeItem: '#js_addMemberIframe', //iframe元素
            submitBtn: '.js_submit',
        });

        //移除成功
        $(".js_quitProjectBtn").click(function(event){
            // 阻止事件冒泡
            event.stopPropagation();

            var thisObj = $(this);

            var memberId    = thisObj.data('id');

            var url = "{{url('member/delete')}}";

            confirm('确认将该成员移出项目?', function(){

                $.post(url, { member_id:memberId }, function(json){

                    if(json.code == 200){

                        alert(json.msg, 500, function () {
                            thisObj.closest('tr').remove();
                        });

                    }else{

                        alert(json.msg, 2000);

                    }

                }, 'json');
            });

        });

    });
</script>

{{include_file name='public/footer'}}